package net.infobank.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class SendSMS
 */
@WebServlet(
		urlPatterns = { "/SendSMS" }, 
		initParams = { 
				@WebInitParam(name = "recipient", value = ""), 
				@WebInitParam(name = "content", value = ""), 
				@WebInitParam(name = "sender", value = "")
		})
public class SendSMS extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SendSMS() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess( request, response );
	}



	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess( request, response );
	}
	
	private void doProcess( HttpServletRequest request, HttpServletResponse response ) throws IOException {

		String recipient = request.getParameter( "recipient" );
		String content = request.getParameter( "content" );
		String sender = request.getParameter( "sender" );
		
		response.setContentType("text/html; charset=UTF-8");

        // Response 객체의 PrintWriter를 사용해 브라우저에 HTML을 출력한다.
        PrintWriter out = response.getWriter();
        out.println("<HTML><HEAD><TITLE>SendSMSServlet</TITLE></HEAD>");
        out.println("<BODY>");
        out.println("<H2> Clinet IP: " + request.getRemoteAddr() + "</H2>");
        out.println("<H2> Client Host : " + request.getRemoteHost() + "</H2>");
        out.println("<H2> Request URI : " + request.getRequestURI() + "</H2>");
        out.println("<H2> Recipient : " + recipient + "</H2>");
        out.println("<H2> Content : " + content + "</H2>");
        out.println("<H2> Sender : " + sender + "</H2>");
	}

}
